package com.xzy.config;

import com.xzy.demo.filterConfig.LoggingInterceptor;
import org.springframework.boot.autoconfigure.web.format.DateTimeFormatters;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.Formatter;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.*;

import java.util.Date;
import java.util.Locale;

@Configuration
/*这个注解加了，自动配置类不生效*//*这个注解加了，自动配置类不生效*/
/*@EnableWebMvc*/
public class MyMvcConfig implements WebMvcConfigurer {

    //diy视图 @Bean 交给springboot 自动装配，在dispatchServlet 中的 doDispatch  方法可以看到
    @Bean
    public MyViewResolver getMyViewResolver(){
        return new MyViewResolver();
    }
    //国际化
    @Bean
    public LocaleResolver localeResolver(){
        return new MyLocaleResolver();
    }


    /*格式化*/
    @Override
    public void addFormatters(FormatterRegistry registry) {

    }

    /*拦截器*/
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoggingInterceptor()).addPathPatterns("/**")
                .excludePathPatterns("/","/index","/css/**","/img/**","/js/**","/login");
    }
    /*视图跳转*/
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("index");
        registry.addViewController("/index").setViewName("index");
        registry.addViewController("/index.html").setViewName("index");
    }
    /*静态资源*/

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

    }

    //扩展视图解析器
    public static class MyViewResolver implements ViewResolver{
        @Override
        public View resolveViewName(String s, Locale locale) throws Exception {
            return null;
        }
    };



}
